<?php
require_once('db.php');

//Params;
$module 	= $_GET['module'];
$view 		= $_GET['view'];

if (($_GET['module']!='') && ($_GET['view']!='')){
	$module 	= $_GET['module'];
	$view 		= $_GET['view'];
} else {
	$module 	= $_POST['module'];
	$view 		= $_POST['view'];
}

$cat_id		= $_GET['category_id'];
$per_page	= $_GET['per_page'];
$prod_id	= $_GET['prod_id'];

//Start of pos module
if ($module == 'pos'){

//1.Load product By Categry :
if ($view=='catalog'){
	
	if(isset($_GET['pageId']) && !empty($_GET['pageId'])){
		$page=$_GET['pageId'];
	}else{
		$page=1;
	}
	
	$offset	= ($page - 1) * $per_page;

    
	$content = "";
  
	$sql 		= 	"select * from tb_product where prod_cat='$cat_id' order by prod_id asc limit $offset,".$per_page;
	$result 	=  	@mysql_query($sql,$link);  
	$count	=	@mysql_num_rows($result);
  
  
  
	if($count > 0){
		while($data_get=@mysql_fetch_array($result)){
			$content .= "<button type=\"button\" class=\"btn btn-prni\" value=\"".$data_get['retail_price']."\" id=\"product-".$data_get['prod_id']."\" data-name=\"".$data_get['prod_name']."\">".$data_get['prod_name']."<img src=\"".$data_get['prod_img']."\" alt=\"".$data_get['prod_name']."\" style=\"width: 150px; height: 150px;\"></button>\n";
		}
		$content	.=	"<div></div>";
		echo $content;
	}
  
} 

elseif ($view=='total_cp'){
  $sql 		= "select prod_id from tb_product where prod_cat='$cat_id'";
  $result 	=  @mysql_query($sql,$link);  
  echo @mysql_num_rows($result);
  
} 

elseif ($view=='getFavourite'){
  $sql 		= "select * from tb_category where status='F' order by id desc limit 1";
  $result 	=  @mysql_query($sql,$link);  
  $row =  @mysql_fetch_array($result);
  echo $row[0];
  
} 


elseif ($view=='current_sales'){
 $content = "";
 $curr_date =  date("Y-m-d");
 $sql = "SELECT paidby, SUM(grand_tot) as total FROM  `tb_sales` where status='P' and DATE_FORMAT(datetime,'%Y-%m-%d')='".$curr_date."' GROUP BY paidby ";
 $result 	= @mysql_query($sql,$link);
 $row		= @mysql_num_rows($result);
 $total = 0.00;
 while($data_get=@mysql_fetch_array($result)){	
		$total +=  $data_get['total'];
		$content .= "<tr><td width=\"50%\">".$data_get['paidby']."</td><td width=\"2%\">:</td><td width=\"48%\" style=\"text-align: right;\">".number_format($data_get['total'],2,'.',',')."</td></tr>\n";
 }
 $content .= "<tr><td width=\"50%\"><strong>TOTAL SALES</strong></td><td width=\"2%\">:</td><td width=\"48%\"  style=\"text-align: right;\"><strong>".number_format($total,2,'.',',')."</strong></td></tr>\n";
 if ($row>0){ 
	echo $content;
 } else { echo "<i>Data Sales Posisi [".date('Y-m-d h:m:s')."] Kosong...</i>";}
}


}//end of pos module 

if ($module=='auth') {

}

mysql_close($link);
?>